package cn.wolfcode.ssm.service.impl;

import cn.wolfcode.ssm.domain.CourseOrder;
import cn.wolfcode.ssm.domain.Employee;
import cn.wolfcode.ssm.mapper.CourseOrderMapper;
import cn.wolfcode.ssm.mapper.CustomerMapper;
import cn.wolfcode.ssm.qo.QueryObject;
import cn.wolfcode.ssm.service.ICourseOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseOrderServiceImpl implements ICourseOrderService {

    @Autowired
    private CourseOrderMapper courseOrderMapper;

    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public void delete(Long id) {
        courseOrderMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void save(CourseOrder courseOrder) {
        courseOrder.setInputTime(new Date());
        Integer status = courseOrder.getCustomer().getStatus()+1;
        Long customerId = courseOrder.getCustomer().getId();
        customerMapper.changeStatus(customerId,status);
        courseOrderMapper.insert(courseOrder);
    }

    @Override
    public CourseOrder getOne(Long id) {
        return courseOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CourseOrder> getAll() {
        return courseOrderMapper.selectAll();
    }

    @Override
    public void update(CourseOrder courseOrder) {
        courseOrder.setInputTime(new Date());
        courseOrderMapper.updateByPrimaryKey(courseOrder);
    }


    @Override
    public PageInfo<CourseOrder> selctForPageResult(QueryObject qo) {
        //使用分页插件,传入当前页,每页显示数量
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<CourseOrder> courseOrders = courseOrderMapper.selectForResult(qo);
        return new PageInfo(courseOrders);
    }
}
